package com.fortune.rainshinecommon.core;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @program: rainShine
 * @description: 用户session
 * @author: tangyn
 * @create: 2019-02-23
 **/
public class UserSession implements java.io.Serializable {
    private String unionUid;
    private String name;
    private String userId;
    private String token;
    /*
     *当前城市
     */
    private String currentCityCode;
    /**
     * 当前省份
     */
    private String currentProvinceCode;
    /**
     * 当前城市名
     */
    private String cityName;
    /**
     * 当前城市pinyin名称
     */
    private String cityPyName;
    /**
     * 扩展参数
     */
    private Map<String, Object> params = new HashMap<>();

    public String getUnionUid() {
        return unionUid;
    }

    public void setUnionUid(String unionUid) {
        this.unionUid = unionUid;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getCurrentCityCode() {
        return currentCityCode;
    }

    public void setCurrentCityCode(String currentCityCode) {
        this.currentCityCode = currentCityCode;
    }

    public String getCurrentProvinceCode() {
        return currentProvinceCode;
    }

    public void setCurrentProvinceCode(String currentProvinceCode) {
        this.currentProvinceCode = currentProvinceCode;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public String getCityPyName() {
        return cityPyName;
    }

    public void setCityPyName(String cityPyName) {
        this.cityPyName = cityPyName;
    }

    public void addParam(String name, Object value) {
        params.put(name, value);
    }

    @SuppressWarnings("unchecked")
    public <P> Optional<P> getParam(String name) {
        Object o = params.get(name);
        if (o == null) {
            return Optional.empty();
        }
        return Optional.of((P) o);
    }

    public void removeParam(String name) {
        params.remove(name);
    }
}
